package src;



import java.sql.*;

public class Jdbc_setup {


	public static void main(){

		String userName = "root"; 
		String password = "root";
		String host = "jdbc:mysql://localhost:3306/";
		String dbName = "Youtube";
		Connection conn = null;
		String command ="";

		//Driver testing
		try {
			Class.forName("com.mysql.jdbc.Driver");
			//			Class.forName("oracle.jdbc.driver.OracleDriver");
		} catch (ClassNotFoundException cnfe) {
			System.out.println("Error loading driver: " + cnfe);
		}

		//Establishing connnection

		Statement stmt = null;
		String tablename= "youtube";
		try{
			conn = DriverManager.getConnection(host+dbName,userName,password);
			stmt = conn.createStatement();

		}
		catch(Exception e){
			System.out.println("Error establishing connection");

		}

		//Executing query
		try{

			stmt.executeUpdate("use "+tablename+";");
			command="create table video(title varchar2(50), uploaded_by varchar2(50), id varchar2(13) Primary key, description varchar2(250), keywords varchar2(250), views int, favourites int , rating float);";
			//stmt.executeUpdate(command);
			//stmt.executeUpdate("insert into video(\"MY\",\"Chirag\",\"xs32fww4ew3\",\"My first video\",\"rocking, awesome, best, iiitd\",123,3456,4.234);");
			//insert into video values("MY","Chirag","xs32fww4ew3","My first video","rocking.awesome.best.iiitd",123,3456,4.234);
			//insert into video values('MY','Chirag','xs32fww4ew3','My first video','rocking.awesome.best.iiitd',123,3456,4.234);
		}
		catch(Exception e){
			System.out.println("Error executing command");
		}


	}
}
